package tyk.common;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*
* 全局异常处理器
* 用来捕获异常，保证程序正常运行的
* */
@RestControllerAdvice
@Component
public class MyExceptionHandler {

    /*
    * 捕获自定义异常
    * 并且向前端返回封装好的Result JSON对象
    * */
    @ExceptionHandler(MyException.class)
    public Result<String> run(MyException e) {
        return Result.error(e.getMessage());
    }

}
